package com.wie.staffhubpro.controller;

import com.wie.staffhubpro.domain.dto.LeavaApplicationDTO;
import com.wie.staffhubpro.domain.dto.PermitLeaveAppDTO;
import com.wie.staffhubpro.domain.dto.SearchLeaveAppDTO;
import com.wie.staffhubpro.domain.entity.LeaveApplication;
import com.wie.staffhubpro.domain.entity.Result;
import com.wie.staffhubpro.domain.vo.LeaveApplicationVO;
import com.wie.staffhubpro.service.LeaveApplicationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/leaveApp")
public class LeaveApplicationController {

    @Autowired
    private LeaveApplicationService leaveApplicationService;

    /**
     * 提交请假申请
     */
    @PostMapping("/submit")
    public Result submit (@RequestBody LeavaApplicationDTO leavaApplicationDTO) {
        log.info("提交请假申请: {}", leavaApplicationDTO);
        leaveApplicationService.submit(leavaApplicationDTO);
        return Result.success();
    }

    /**
     * 审批请假申请
     */
    @PostMapping("/permit")
    public Result permit (@RequestBody PermitLeaveAppDTO permitLeaveAppDTO) {
        log.info("审批请假申请: {}", permitLeaveAppDTO);
        leaveApplicationService.permit(permitLeaveAppDTO);
        return Result.success();
    }

    /**
     * 查询个人请假信息
     */
    @PostMapping("/getByEmpId")
    public Result getByEmpId (@RequestBody SearchLeaveAppDTO searchLeaveAppDTO) {
        log.info("查询个人请假信息: {}", searchLeaveAppDTO);
        List<LeaveApplication> leaveApplicationList = leaveApplicationService.getByEmpId(searchLeaveAppDTO);
        return Result.success(leaveApplicationList);
    }

    /**
     * 查询部门请假信息
     */
    @PostMapping("/getByDeptId")
    public Result getByDeptId (@RequestBody SearchLeaveAppDTO searchLeaveAppDTO) {
        log.info("查询部门请假信息: {}", searchLeaveAppDTO);
        List<LeaveApplication> leaveApplicationList = leaveApplicationService.getByDeptId(searchLeaveAppDTO);
        return Result.success(leaveApplicationList);
    }

}
